package com.jiutong.meipenggang.http.present;

import android.content.Context;

import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.MainPageBean;
import com.jiutong.meipenggang.entity.MyInverstBean;
import com.jiutong.meipenggang.entity.TotalMoneyBean;
import com.jiutong.meipenggang.http.model.interfaces.MainPageBiz;
import com.jiutong.meipenggang.http.model.requests.MainPageRequest;
import com.jiutong.meipenggang.http.subscribers.ProgressSubscriber;
import com.jiutong.meipenggang.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipenggang.utils.SpConfig;
import com.jiutong.meipenggang.utils.TimeUitl;

import java.util.HashMap;

/**
 * Created by bdf on 2017/12/18.
 */

public class MainPagePresent {
    private final Context mContext;
    private final MainPageBiz mainPageBiz;
    private final MainPageRequest pageRequest;

    public MainPagePresent(Context mContext, MainPageBiz mainPageBiz) {
        this.mContext = mContext;
        this.mainPageBiz = mainPageBiz;
        pageRequest = new MainPageRequest();
    }

    /**
     * 主页接口
     */

    public void MainPage() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<MainPageBean>() {
            @Override
            public void onNext(MainPageBean subjects) {
                mainPageBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mainPageBiz.onError(e);
            }

        };
        HashMap<String, Object> fieldsMap = new HashMap<>();
        boolean isLogin = SpConfig.getInstance().getBool(Constants.IS_LOGIN);
        fieldsMap.put("OPT", 21);
        if (isLogin) {
            fieldsMap.put("id", SpConfig.getInstance().getString(Constants.ID));
            fieldsMap.put("token", SpConfig.getInstance().getString(Constants.TOKEN));
        }
        fieldsMap.put("timestamp", TimeUitl.getDate());
        fieldsMap.put("gestureCipher", SpConfig.getInstance().getString(Constants.GESTURE_CIPHER) + "");
        pageRequest.mainPage(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }



    public void MyInverst() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<MyInverstBean>() {
            @Override
            public void onNext(MyInverstBean subjects) {
                mainPageBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mainPageBiz.onError(e);
            }

        };
        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("OPT", 25);
        fieldsMap.put("timestamp", TimeUitl.getDate());
        fieldsMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        fieldsMap.put("token", SpConfig.getInstance().getString(Constants.TOKEN));
        fieldsMap.put("currPage", "1");

        pageRequest.MyInverst(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }



    public void TotalMoney() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<TotalMoneyBean>() {
            @Override
            public void onNext(TotalMoneyBean subjects) {
                mainPageBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mainPageBiz.onError(e);
            }

        };
        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("OPT", 22);
        fieldsMap.put("timestamp", TimeUitl.getDate());
        fieldsMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        fieldsMap.put("token", SpConfig.getInstance().getString(Constants.TOKEN));
        fieldsMap.put("currPage", "1");

        pageRequest.TotalMoney(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }
}
